import { ZePrideComponentSize } from './zepride-component-size';
import { ZePrideDatasourceType } from './zepride-datasource-type';
import { ValidationType } from './validation-type';

/**
 * 组件
 */
export interface ZePrideComponent {
    id?: string;
    tempId?: string; // 用于拖拽时定位的id，不存储
    index?: number;
    labelText?: string;
    name?: string;
    dataSourceType?: ZePrideDatasourceType;
    dataSource?: { key: string; value: any }[] | string;
    size?: ZePrideComponentSize;
    bindField?: string;
    defaultValue?: any;
    authorityId?: string;
    validations?: { type: ValidationType, value?: any }[];
    selector?: string;
    showMask?: boolean;
    readonly?: boolean;
    extends?: any; // 组件的扩展属性
    identifyId?: string;
    condition?: any;
    perimitConfig?: {
        permitSelected?: boolean;
        permitId?: string;
        permitName?: string;
        refObjectType?: string;
        refObjectId?: string;
        authObjectId?: string;
        authObjectType?: string;
        mode?: string;
    }[];
}

export interface TableField {
    name: string;
    bindField: string;
}

export interface ExConfigOption {
    fields: {
        type: ConfigOptionType;
        field: ExConfigOptionValueField;
    }[];
    onSave?: () => void;
}

export declare type ConfigOptionType = 'input' | 'select' | 'modal';

export interface ExConfigOptionValueField {
    name?: string;
    propertyName?: string;
    validations?: ExConfigOptionValidations;
    editConfig?: () => void;
    options?: {
        value: any;
        label: string;
    }[];
}

export interface ExConfigOptionValidations {
    required?: boolean;
    max?: number;
    min?: number;
    pattern?: RegExp;
    maxLength?: number;
    minLength?: number;
}
